package com.yunkeji.api.call.controller;

import cn.hutool.json.JSONUtil;
import com.yunkeji.api.call.bo.RtcContentCheckBo;
import com.yunkeji.api.call.bo.RtcRecordCallBackBo;
import com.yunkeji.api.call.bo.RtcRoomCallBackBo;
import com.yunkeji.api.call.service.CallService;
import com.yunkeji.common.core.controller.BaseController;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 回调
 *
 * @author 老张
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/tencentrtc/call")
@Slf4j
public class CallbackController extends BaseController {
    private final CallService callService;

    /** 腾讯云回调-进入房间和离开房间 */
    @PostMapping("/roomCallback")
    public void roomCallback(@RequestBody RtcRoomCallBackBo rtcRoomCallBackBo) {
        if (rtcRoomCallBackBo.getEventType().equals(RtcRoomCallBackBo.EventType.进入房间.getCode())) {
            log.info("接收到腾讯云进入房间回调->{}", JSONUtil.toJsonStr(rtcRoomCallBackBo));
            callService.callbackEnter(rtcRoomCallBackBo);
        }
        if (rtcRoomCallBackBo.getEventType().equals(RtcRoomCallBackBo.EventType.退出房间.getCode())) {
            log.info("接收到腾讯云退出房间回调->{}", JSONUtil.toJsonStr(rtcRoomCallBackBo));
            callService.callbackLeave(rtcRoomCallBackBo);
        }
    }

    /** 语音内容实时监测 */
    @PostMapping("/rtcContentCheck")
    public void rtcContentCheck(@RequestBody RtcContentCheckBo rtcContentCheck) {
        callService.rtcContentCheck(rtcContentCheck);
    }

    /** 开始录音回调-在这里启动录音检查任务 */
    @PostMapping("/startRecord")
    public void startRecord(@RequestBody RtcRecordCallBackBo bo) {
        callService.startRecord(bo);
    }
}
